<%@ page contentType="text/html; charset=UTF-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link type="text/css" href="/css/logicss/common.css" rel="stylesheet" />
<link type="text/css" href="/css/logicss/print.css" rel="stylesheet" media = "print"/>
<link type="text/css" href="/css/logicss/utils.css" rel="stylesheet" />
<link type="text/css" href="/css/logicss/e24m.css" rel="stylesheet" />
<link type="text/css" href="/css/logicss/dark.css" rel="stylesheet" />
<style type="text/css" media="screen">
        @import '/css/logicss/utils.css';
        @import '/css/logicss/mix.css';
        @import '/css/logicss/small.css';
        @import '/css/logicss/e24m.css';
        @import '/css/logicss/dark.css';
        @import '/css/logicss/common.css';
        #nav-site { margin-top: 1.75em; }
    </style>
<script type="text/javascript">

var obj = null;
function ab()
{
	var label = document.getElementById(obj);
	var str = document.getElementById("string");
	label.innerText = str.value;
	obj = null;
}

function edit(id)
{ 
	if(obj!=id)
	{ 
		if(obj!=null)
		{ab();}
		obj = id;
		var lable = document.getElementById(id);
		var l = lable.innerText;
		lable.innerHTML = "<input type='text' id='string' onblur='ab()'></input>";
		var str = document.getElementById("string");
		str.focus();
		str.value=l;
	}
}

function add()
{
	var form = document.getElementById("fortifierData");
	form.name.value = document.getElementById("1").innerText;
	form.unit.value = document.getElementById("2").innerText;
	form.nutriment.value = document.getElementById("3").innerText;
	form.ratio.value = document.getElementById("4").innerText;
	form.purity.value = document.getElementById("5").innerText;
	form.cost.value = document.getElementById("6").innerText;
	form.lose.value = document.getElementById("7").innerText;
	form.discription.value = document.getElementById("8").innerText;
	form.operation.value = 1;
	form.submit();
}

function save()
{
	var form = document.getElementById("fortifierData");
	form.name.value = document.getElementById("1").innerText;
	form.unit.value = document.getElementById("2").innerText;
	form.nutriment.value = document.getElementById("3").innerText;
	form.ratio.value = document.getElementById("4").innerText;
	form.purity.value = document.getElementById("5").innerText;
	form.cost.value = document.getElementById("6").innerText;
	form.lose.value = document.getElementById("7").innerText;
	form.discription.value = document.getElementById("8").innerText;
	form.operation.value = 2;
	form.submit();
}


function erase()
{
	var form = document.getElementById("deleteData");
	//alert(form.id.value);
	form.submit();
}


function checkForm()
{
	return true;
}


</script>
<title>Untitled Document</title>
</head>
<body id="page-home" style="background: url(/images/bg.jpg);">
<div id="contanier" class="content grid">
<div>
<div id="section" class="first col w5">
<img id = "logo" alt='logo' src='/images/logos/logo_small.jpg' width=80 height=40/>
</div>
<div id ="content-head" class="last col w6" >
<ol class="h-list" style="margin-top:18px">
<li><a href='#' onclick='add()'>添加</a></li>
<li><a href='#' onclick='save()'>保存</a></li>
<li><a href='#' onclick='erase()'>删除</a></li>
</ol>
</div>

</div>
<hr/>

</div>

<div id ="content-main" class="content grid" >
<div class="first col w5">
<ol class="v-list" style="text-align:left;">
<li><a >名称：</a></li>
<li><a >常用单位：</a></li>
<li><a >强化元素：</a></li>
<li><a >强化剂比例：</a></li>
<li><a >强化剂纯度：</a></li>
<li><a >强化剂单价：</a></li>
<li><a >强化剂工业损失：</a></li>
<li><a >描述：</a></li>
</ol>
</div>

<form method="post" id="fortifierData" onsubmit="return checkForm()">
	<input type="hidden" name="name" />
	<input type="hidden" name="unit" />
	<input type="hidden" name="nutriment" />
	<input type="hidden" name="ratio" />
	<input type="hidden" name="purity" />
	<input type="hidden" name="cost" />
	<input type="hidden" name="lose" />
	<input type="hidden" name="discription" />
	<input type="hidden" name="operation" />
</form>

<div class="last col w5">
<ol class="v-list" style="text-align:left;">
	<%@ page import="java.util.Set" %>
	<%@ page import="db.nutriment.Nutriment" %>
<% 
@SuppressWarnings("unchecked")
Set<Nutriment> nutriment = (Set<Nutriment>)request.getAttribute("nutriments");
String nuit = (String)request.getAttribute("unit");
String name = (String)request.getAttribute("name");
String ratio = (String)request.getAttribute("ratio");
String purity = (String)request.getAttribute("purity");
String cost = (String)request.getAttribute("cost");
String loss = (String)request.getAttribute("loss");
String des = (String)request.getAttribute("description");
String id = (String)request.getAttribute("id");
out.print("<li><a id='1' onclick='edit(this.id)' href='#'>"+name+"</a></li>");
out.print("<li><a id='2' onclick='edit(this.id)' href='#'>"+nuit+"</a></li>");

for(int i = 0;i<nutriment.size();i++){
out.print("<li><a id='3' onclick='edit(this.id)' href='#'>"+((Nutriment)(nutriment.toArray()[i])).getName()+"</a></li>");
}
out.print("<li><a id='4' onclick='edit(this.id)' href='#'>"+ratio+"</a></li>");
out.print("<li><a id='5' onclick='edit(this.id)' href='#'>"+purity+"</a></li>");
out.print("<li><a id='6' onclick='edit(this.id)' href='#'>"+cost+"</a></li>");
out.print("<li><a id='7' onclick='edit(this.id)' href='#'>"+loss+"</a></li>");
out.print("<li><a id='8' onclick='edit(this.id)' href='#'>"+des+"</a></li>");
%>
</ol>

<form method = "post" id = "deleteData" action="/fortifier/removeFortifier.do">
<%
out.print("<input type='hidden' name='id' value= '"+id+"' /> "); 
%>
</form>

</div>
</div>
</body>
</html>